﻿using LiteDB;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AdministratorHelper
{
    public class AppDb
    {

        private LiteDatabase db;
        private LiteCollection<AppModel> col;

        public AppDb()
        {
            db = new LiteDatabase(@"app.db");
            col = db.GetCollection<AppModel>("app");
        }

        public bool IsExist(string appName)
        {
            return col.FindOne(x => x.AppName == appName) != null;
        }

        public int Create(AppModel app)
        {
            var r = col.Insert(app);
            return r.AsInt32;
        }

        public bool Delete(string appName)
        {
            return col.Delete(x => x.AppName == appName) > 0;
        }


        public AppModel Get(string appName)
        {
            return col.FindOne(x => x.AppName == appName);
        }

        public List<AppModel> GetAll()
        {
            return col.FindAll().ToList<AppModel>();
        }
    }
}
